//
//  NewHomePlatformItemCell.swift
//  d11
//
//  Created by peale_pro on 2019/6/27.
//  Copyright © 2019年 Tech_001. All rights reserved.
//

import UIKit
import Lottie


class NewHomePlatformItemCell: UICollectionViewCell {
    var iconImgView: UIImageView?
    var iconAnimationView : AnimationView?
    var titleLabel: UILabel?
    var isPay :Bool = false
    var lineView :UIView?
    var lineViewY :UIView?
    override init(frame:CGRect){
        super.init(frame: frame)
        setUpUI()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setUpUI() -> Void {
        self.backgroundColor  = UIColor.clear
        //  self.selectionStyle = UICollectionViewCell.SelectionStyle.none
        self.iconImgView = UIImageView.init(image: imageNamed("login_logo"))
        self.contentView.addSubview(self.iconImgView!)
        self.iconImgView?.snp.makeConstraints{(make) in
            make.width.equalTo(35)
            make.height.equalTo(35)
            make.centerX.equalToSuperview()
            make.top.equalTo(30)
        }
        self.iconAnimationView = AnimationView.init()
        self.contentView.addSubview(self.iconAnimationView!)
        self.iconAnimationView?.snp.makeConstraints{(make) in
            make.width.equalTo(35)
            make.height.equalTo(35)
            make.centerX.equalToSuperview()
            make.top.equalTo(30)
        }
        self.titleLabel = UILabel.init()
        self.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        titleLabel?.textColor = HexRGBAlpha(0x747474, 1)
        titleLabel?.textAlignment = .center
        self.contentView.addSubview(self.titleLabel!)
        self.titleLabel?.snp.makeConstraints{(make) in
            make.width.equalToSuperview()
            make.height.equalTo(20)
            make.centerX.equalToSuperview()
            // make.top.equalTo((self.iconAnimationView?.snp.bottom)!).offset(10)
            make.top.equalTo(75)
        }
        
        self.lineView = UIView.init()
        self.lineView?.backgroundColor = HexRGBAlpha(0xffc569, 0.8)
        self.contentView.addSubview(self.lineView!)
        self.lineView?.snp.makeConstraints{(make) in
            make.left.equalToSuperview().offset(25)
            make.height.equalTo(0.5)
             make.right.equalToSuperview().offset(-25)
           // make.centerX.equalToSuperview()
            // make.top.equalTo((self.iconAnimationView?.snp.bottom)!).offset(10)
            make.bottom.equalToSuperview().offset(-6)
        }
        self.lineViewY = UIView.init()
        self.lineViewY?.backgroundColor = HexRGBAlpha(0xffc569, 0.8)
        self.contentView.addSubview(self.lineViewY!)
        self.lineViewY?.snp.makeConstraints{(make) in
            make.right.equalToSuperview().offset(-3)
            make.width.equalTo(0.5)
            make.top.equalToSuperview().offset(20)
            make.bottom.equalToSuperview().offset(-20)
        }
    }
    
    func setData(imgUrl:String,selImgUrl:String,title:String,isSelect:Bool,row:Int,count:Int) -> Void {
        titleLabel?.text = title
        if (row+1) % 2 == 0 {
            self.lineViewY?.isHidden = true
        }else{
            self.lineViewY?.isHidden = false
        }
        if row+2 == count || row+1 == count{
            print("\(row)--\(count)")
            self.lineView?.isHidden = true
        }else{
             self.lineView?.isHidden = false
        }
        if self.iconAnimationView != nil{
            self.iconAnimationView?.removeFromSuperview()
            self.iconAnimationView = nil
        }
        if isSelect == true {
            
//            self.iconAnimationView = AnimationView.init(contentsOf: URL(string: selImgUrl)!)
            self.iconAnimationView = AnimationView.init(url: URL(string: selImgUrl)!, closure: {
                down in
            })
            self.isPay = true
            self.titleLabel?.textColor = HexRGBAlpha(0xffc569, 1)
            self.contentView.addSubview(self.iconAnimationView!)
            self.iconAnimationView?.snp.makeConstraints{(make) in
                make.width.equalTo(35)
                make.height.equalTo(35)
                make.centerX.equalToSuperview()
                make.top.equalTo(30)
            }
            
            
        }else{
            //self.iconImgView?.sd_setImage(with: URL(string: imgUrl), placeholderImage: imageNamed("icon_newhome_platform_zwt_bg_noselect"), options: .refreshCached, completed: nil)
            self.iconAnimationView = AnimationView.init(url: URL(string: selImgUrl)!, closure: {
                down in
            })
            self.titleLabel?.textColor = HexRGBAlpha(0x747474, 1)
            self.contentView.addSubview(self.iconAnimationView!)
            self.iconAnimationView?.snp.makeConstraints{(make) in
                make.width.equalTo(35)
                make.height.equalTo(35)
                make.centerX.equalToSuperview()
                make.top.equalTo(30)
            }
            
        }
        
        
        
        self.iconAnimationView?.play(completion: { (animationFinished) in
            
        })
        
        if self.iconAnimationView?.isAnimationPlaying == true{
            self.iconImgView?.isHidden = true
        }else{
            self.iconImgView?.isHidden = false
        }
    }
}
